package com.xyzboom.database.entity;

import java.util.EnumMap;

@Entity
public class Course {
    @EntityColumnEnum
    public enum CourseColumn {
        CID("cId"),
        CNAME("cName"),
        CNUM("cNum"),
        CTYPE("cType"),
        NULL("");
        public final String value;

        CourseColumn(String value) {
            this.value = value;
        }

        public static CourseColumn getColumnNull() {
            return NULL;
        }

        public static CourseColumn fromString(String value) {
            for (CourseColumn c : CourseColumn.values()) {
                if (c.value.equals(value)) {
                    return c;
                }
            }
            return NULL;
        }
    }

    public static Class<? extends Enum<?>> getEntityColumnEnum() {
        return CourseColumn.class;
    }

    @Override
    public String toString() {
        return "Course{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", num=" + num +
                ", type=" + type +
                '}';
    }

    public enum CourseType {
        ELECTIVE("选修"),
        REQUIRED("必修");
        public final String type;

        public String getType() {
            return type;
        }

        CourseType(String type) {
            this.type = type;
        }
    }

    private int id;
    private String name;
    private int num;
    private CourseType type;

    public boolean typeEquals(CourseType type) {
        return this.type.equals(type);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getType() {
        return type.type;
    }

    public void setType(String type) {
        switch (type) {
            case "必修":
            case "REQUIRED":
                this.type = CourseType.REQUIRED;
                break;
            case "选修":
            case "ELECTIVE":
            default:
                this.type = CourseType.ELECTIVE;
                break;
        }
    }

    public Course(int id, String name, int num, CourseType type) {
        this.id = id;
        this.name = name;
        this.num = num;
        this.type = type;
    }

    public Course(int id, String name, int num, String type) {
        this.id = id;
        this.name = name;
        this.num = num;
        setType(type);
    }
}
